#include <stdio.h>

typedef struct {
    int r;
    int g;
    int b;
} COLOR;

int main(int argc, const char *argv[]) {

    COLOR list[16];
    COLOR current;
    int i, d, min_val, min_idx;

    for (i = 0; i < 16; i++) {
        scanf("%d %d %d", &list[i].r, &list[i].g, &list[i].b);
    }

    while (1) {
        scanf("%d %d %d", &current.r, &current.g, &current.b);
        if (-1 == current.r) {
            break;
        }

        min_val = 256 * 256 * 256;
        min_idx = -1;
        for (i = 0; i < 16; i++) {
            d = pow(current.r - list[i].r, 2);
            d += pow(current.g - list[i].g, 2);
            d += pow(current.b - list[i].b, 2);

            if (d < min_val) {
                min_val = d;
                min_idx = i;
            }
        }
        
        printf("(%d,%d,%d) maps to (%d,%d,%d)\n", 
                current.r, current.g, current.b,
                list[min_idx].r, list[min_idx].g, list[min_idx].b);
    }
    
    return 0;
}
